package com.ruoyi.framework.web.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * 缓存操作处理
 * 
 * @author ruoyi
 */
@Service
public class RedisService
{
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    public String get(String key){
        return stringRedisTemplate.opsForValue().get(key);
    }

    public Boolean setnx(String key, String value) {
        return stringRedisTemplate.opsForValue().setIfAbsent(key,value);
    }
    public void set(String key, String value) {
        stringRedisTemplate.opsForValue().set(key,value);
    }
    public void set(String key, String value,Long time) {
        stringRedisTemplate.opsForValue().set(key,value,time,TimeUnit.SECONDS);
    }
    public void del(String key) {
        stringRedisTemplate.delete(key);
    }
    public void expire(String key,Long time) {
        stringRedisTemplate.expire(key,time,TimeUnit.SECONDS);
    }
}
